package com.ruoyi.task.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.task.domain.TaskExamine;
import com.ruoyi.task.domain.TaskManagement;
import com.ruoyi.task.mapper.TaskManagementMapper;
import com.ruoyi.task.service.ITaskExamineService;
import com.ruoyi.task.service.ITaskManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 任务管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-17
 */
@Service
public class TaskManagementServiceImpl implements ITaskManagementService
{
    @Autowired
    private TaskManagementMapper taskManagementMapper;

    @Autowired
    private ITaskExamineService taskExamineService;

    /**
     * 查询任务管理
     * 
     * @param id 任务管理主键
     * @return 任务管理
     */
    @Override
    public TaskManagement selectTaskManagementById(Long id)
    {
        return taskManagementMapper.selectTaskManagementById(id);
    }

    /**
     * 查询任务管理列表
     * 
     * @param taskManagement 任务管理
     * @return 任务管理
     */
    @Override
    public List<TaskManagement> selectTaskManagementList(TaskManagement taskManagement)
    {
        List<TaskManagement> list = taskManagementMapper.selectTaskManagementList(taskManagement);
        for (TaskManagement taskManagement1 : list) {
             taskManagement1.setSatisFaction(0L);
            TaskExamine taskExamine1 = new TaskExamine();
            taskExamine1.setTaskId(taskManagement1.getId());
            taskExamine1.setState("0");
            List<TaskExamine> examinesList =  taskExamineService.selectTaskExamineList(taskExamine1);
            if(!examinesList.isEmpty()){
                taskManagement1.setSatisFaction(1L);
            }
        }
        return list;
    }

    /**
     * 新增任务管理
     * 
     * @param taskManagement 任务管理
     * @return 结果
     */
    @Override
    public int insertTaskManagement(TaskManagement taskManagement)
    {
        taskManagement.setCreateTime(DateUtils.getNowDate());
        return taskManagementMapper.insertTaskManagement(taskManagement);
    }

    /**
     * 修改任务管理
     * 
     * @param taskManagement 任务管理
     * @return 结果
     */
    @Override
    public int updateTaskManagement(TaskManagement taskManagement)
    {
        return taskManagementMapper.updateTaskManagement(taskManagement);
    }

    @Override
    public int updateTaskManagementById(TaskManagement taskManagement) {
        return taskManagementMapper.updateTaskManagementById(taskManagement);
    }

    /**
     * 批量删除任务管理
     * 
     * @param ids 需要删除的任务管理主键
     * @return 结果
     */
    @Override
    public int deleteTaskManagementByIds(Long[] ids)
    {
        return taskManagementMapper.deleteTaskManagementByIds(ids);
    }

    /**
     * 删除任务管理信息
     * 
     * @param id 任务管理主键
     * @return 结果
     */
    @Override
    public int deleteTaskManagementById(Long id)
    {
        return taskManagementMapper.deleteTaskManagementById(id);
    }

    @Override
    public List<TaskManagement> getNewTask(Long userId) {
        return taskManagementMapper.getNewTask(userId);
    }
}
